package cn.lijiajia3515.cairo.auth.domain.mongo;

import cn.lijiajia3515.cairo.mongo.data.AbstractMongo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.MongoId;

import java.io.Serializable;
import java.util.Set;

/**
 * 资源 mongo
 */
@EqualsAndHashCode(callSuper = true)
@Data

@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder(toBuilder = true)
@Accessors(chain = true)
public class ResourceMongo extends AbstractMongo {

	/**
	 * mongo id
	 */
	@MongoId
	private ObjectId _id;

	/**
	 * client
	 */
	private String client;

	/**
	 * 唯一标识
	 */
	private String id;

	/**
	 * 上级id
	 */
	private String parent;

	/**
	 * 类型
	 */
	private Type type;

	/**
	 * 名称
	 */
	private String name;

	/**
	 * 接口所需要的权限标识
	 */
	private Set<String> permissions;

	/**
	 * 前端路径/前端路由/页面地址外部地址
	 */
	private String path;

	/**
	 * 图标
	 */
	private String icon;


	/**
	 * 资源类型
	 */
	public enum Type implements Serializable {
		/**
		 * 菜单
		 */
		MENU,

		/**
		 * 元素
		 */
		ELEMENT;

		public String value = name();
	}

	public static final Field FIELD = new Field();

	public static final class Field extends AbstractMongo.Field {
		private Field() {

		}

		public final String CLIENT = field("Client");
		public final String ID = field("Id");
		public final String PARENT = field("Parent");
		public final String TYPE = field("Type");
		public final String NAME = field("Name");
		public final String PERMISSIONS = field("Permissions");
		public final String PATH = field("Path");
		public final String ICON = field("Icon");
	}
}
